package jhavelogger.visitor;

import static org.junit.Assert.*;

import java.util.Date;

import jhavelogger.models.AcceptedConnection;
import jhavelogger.models.SendAlgorithmToClient;
import jhavelogger.models.UsernameLookup;
import jhavelogger.models.UidOperation;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

/**
 * Ensures that the reflection-based visitor operates properly using a test (toString) visitor.
 * @author Jared Schlicht
 */
public class VisitorReflectionTests {
    private LogVisitor visitor;
    
    @Before
    public void setUp() {
	this.visitor = new DebuggingVisitor();
    }
    
    @Test
    public void testVisitAcceptedConnection() {
	AcceptedConnection log = new AcceptedConnection("127.0.0.1", 13, "141.233.16.22");
	String result = (String)this.visitor.visit(log);
	Assert.assertEquals(log.toString(), result);
    }

    @Test
    public void testVisitUsernameLookup() {
	UsernameLookup log = new UsernameLookup("127.0.0.1", "bob@gmail.com");
	String result = (String)this.visitor.visit(log);
	Assert.assertEquals(log.toString(), result);
    }

    @Test
    public void testVisitSendAlgorithmToClient() {
	SendAlgorithmToClient log = new SendAlgorithmToClient("127.0.0.1", new Date(2010, 04, 10), "sutherlandhodgman/shc_exercise_3");
	String result = (String)this.visitor.visit(log);
	Assert.assertTrue(result.contains("sutherlandhodgman/shc_exercise_3"));
    }
    
    @Test
    public void testVisitUidOperation() {
	UidOperation log = new UidOperation("127.0.0.1", 1312);
	String result = (String)this.visitor.visit(log);
	Assert.assertEquals(log.toString(), result);
    }
}
